package com.zm.admin.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/***
 *
 * @Auther: MuYun
 * @Date: 2024/4/22 16:22
 * @Description：RabbitMQ配置类
 *
 */
@Configuration
public class RabbitConfig {

    //普通交换机名
    public static final String EXCHANGE_N="zm_n_e";

    //普通队列名
    public static final String QUEUE_N="zm_n_q";

    public static final String RK_N="zm_n_rk";

    //声明普通交换机
    @Bean("xExchange")//这个属性貌似只跟下面的@Qualifier引用的有关
    public DirectExchange xExchange(){
        return new DirectExchange(EXCHANGE_N);
    }

    //声明普通队列，ttl（过期时间）为10s
    @Bean("queueA")
    public Queue queueA(){
        Map<String, Object> map = new HashMap<>(3);
        map.put("x-message-ttl",10000);
        return QueueBuilder.durable(QUEUE_N).withArguments(map).build();
    }

    @Bean
    public Binding queueABindingX(@Qualifier("queueA")Queue queueA, @Qualifier("xExchange")DirectExchange xExchange){
        return BindingBuilder.bind(queueA).to(xExchange).with(RK_N);//zm_notice_routingkey
    }
}
